<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('码盘收货管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="gysmc" name="gysmc" placeholder="供应商名称"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="asnbh" name="asnbh" placeholder="ASN编号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">PO编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="dycgdbh" name="dycgdbh" placeholder="关联PO编号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="stime" id="stime"
                                   placeholder="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent"
                           data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal">重置</button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">ASN状态</label>
                            <div class="layui-input-inline">
                                <select id="asnzt" name="asnzt" class="selector" lay-filter="aihao">
                                    <option value=""></option>
                                    <option value="0">初始</option>
                                    <option value="1">部分收货</option>
                                    <option value="2">完全收货</option>
                                    <option value="3">订单取消</option>
                                    <option value="4">订单完成</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button tpl-button" id="toolbar">

                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            tablebtn = layui.tablebutton,
            laydate = layui.laydate;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*部分收货*/
                editEvent: function (data) {
                   if (data.row != undefined) {
                        bf_Dialog(data.row.id);
                    }
                },
                /*确认收货*/
                confirmEvent: function (data) {
                    if (data.row != undefined) {
                        editDialog(data.row.id);
                    }
                },
                /*取消收货*/
                cancelBh: function (data) {
                    if (data.row != undefined) {
                        startDialog(data.row.id);
                    }
                }
            }
        });


        //确认收货
        function editDialog(id) {
            zzpUtils.dialog({
                title: "确认收货",
                type: 2,
                content: "/mpsh/qrMpsh?id=" + id,
                area: ['93%', '93%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        //部分收货
        function bf_Dialog(id) {
            zzpUtils.dialog({
                title: "部分收货",
                type: 2,
                content: "/mpsh/bfsh?id=" + id,
                area: ['93%', '93%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        //取消收货
        function startDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("您将该单取消收货", function (index) {
                zzpUtils.action({
                    url: "/wmsreceiving/rollBackReceiving",
                    data: JSON.stringify({ids: ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if (data.type == 'success') {
                                layer.msg(data.title);
                            } else {
                                layer.msg(data.message);
                            }

                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }

        laydate.render({
            elem: '#stime'
            , theme: '#20a0ff'
            , range: '~'//练起来
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination: true,
            url: '/wmsEstimatedArrivalOrder/seachSorting',
            columns: [/*{
                field: '',
                checkbox: true
            },*/ {
                field: 'ckmc',
                title: '仓库'
            }, {
                field: 'hzmc',
                title: '货主'
            }, {
                field: 'asnbh',
                title: 'ASN编号'
            }, {
                field: 'show_asnlx',
                title: 'ASN类型'
            }, {
                field: 'show_asnzt',
                title: 'ASN状态'
            }, {
                field: 'yxj',
                title: '优先级',
                visible: false
            }, {
                field: 'cjsj',
                title: '创建时间',
                visible: false
            }, {
                field: 'show_shzt',
                title: '审核状态',
                visible: false
            }, {
                field: 'zdr',
                title: '制单人',
                visible: false
            }, {
                field: 'ddshr',
                title: '审核人',
                visible: false
            }, {
                field: 'show_dyzt',
                title: '打印状态',
                visible: false
            }, {
                field: 'gysmc',
                title: '供应商名称',
                visible: false
            }, {
                field: 'show_mpzt',
                title: '码盘状态',
                visible: false
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            operateFormatter: operateFormatter


        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var  button = '', buttons1 = '', buttons2 = '';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.asnzt == '0') {//初始
                    if (functions.tableBtn[i].name == '确认收货') {
                        buttons1 += btn;
                    }
                } else if(row.asnzt == '1'){//部分收货
                    if (functions.tableBtn[i].name == '部分收货'|| functions.tableBtn[i].name == '取消收货') {
                        buttons1 += btn;
                    }
                }else if(row.asnzt == '2'||row.asnzt == '4'){//完全收货
                    if (functions.tableBtn[i].name == '取消收货') {
                        buttons1 += btn;
                    }
                }
            }
            return buttons1;

           /* var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.asnzt == '0') {//初始
                    if (functions.tableBtn[i].name == '确认收货') {
                        button += btn;
                    }
                } else if (row.asnzt == '1') {//部分收货
                    if (functions.tableBtn[i].name == '部分收货' || functions.tableBtn[i].name == '取消收货') {
                        button += btn;
                    }
                } else if (row.asnzt == '2'||row.asnzt == '4') {//完全收货
                    if (functions.tableBtn[i].name == '取消收货') {
                        button += btn;
                    }
                }*/

            // }
            //     button += '</span>'
            //         + '</div>';
            //     return button;
        }


    });


</script>
</html>